package com.lsa.letcode.the21.mergeSortedLists;


import org.junit.Assert;
import org.junit.Test;

import com.lsa.letcode.common.LetCodeTestBase;
import com.lsa.letcode.common.ListNode;

public class MergeSortedListsTest extends LetCodeTestBase {
	@Test
	public void test(){
		Solution s = new Solution();
		test(s, new int[] { 10, 20, 30 }, new int[] { 1, 11, 25 }, new int[] {
				1, 10, 11, 20, 25, 30 });
		test(s, new int[] { 5, 7, 10, 20, 30,31,32 }, new int[] { 1, 11, 25 }, new int[] {
				1, 5, 7, 10, 11, 20, 25, 30,31,32 });
		test(s, new int[] { 10 }, new int[] { 1 }, new int[] { 1, 10 });
		test(s, new int[] { 10 }, new int[] {}, new int[] { 10 });
		test(s, new int[] { 10, 20, 30 }, new int[] {},
				new int[] { 10, 20, 30 });
		test(s, new int[] {}, new int[] { 10, 20, 30 },
				new int[] { 10, 20, 30 });
		
		test(s, new int[] { 30 }, new int[] { 10, 20, 30 }, new int[] { 10, 20,
				30, 30 });
		
		test(s, new int[] { 11, 29, 30 }, new int[] { 10, 20, 30 }, new int[] { 10, 11, 20,
				29, 30, 30 });
	}

	private void test(Solution s, int[] arr1, int[] arr2, int[] arr3) {
		ListNode l1 = asList(arr1);
		ListNode l2 = asList(arr2);
		ListNode actual = s.mergeTwoLists(l1, l2);
		Assert.assertTrue(""+actual, areEqual(actual, asList(arr3)));
	}
}